<template>
  <div class="my-orders">
    <div class="orders-card">
      <!-- 返回按钮 -->
      <div class="back-button" @click="$router.back()">
        <i class="el-icon-arrow-left"></i>
        <span>返回</span>
      </div>

      <h2 class="section-title">我的订单</h2>

      <!-- 订单状态筛选 -->
      <div class="order-tabs">
        <el-radio-group v-model="currentTab" size="medium">
          <el-radio-button
            v-for="tab in tabs"
            :key="tab.value"
            :label="tab.value"
          >
            {{ tab.label }}
            <el-badge v-if="tab.count" :value="tab.count" class="tab-badge" />
          </el-radio-button>
        </el-radio-group>
      </div>

      <!-- 订单列表 -->
      <div class="orders-list">
        <order-item
          v-for="order in filteredOrders"
          :key="order.id"
          :order="order"
        />
      </div>

      <!-- 温馨提示 -->
      <div class="service-notice">
        <div class="notice-content">
          <i class="el-icon-warning-outline"></i>
          <span>如有任何问题，请申请售后，客服将在24小时内处理。</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import OrderItem from '@/components/OrderItem.vue';

export default {
  name: "MyOrdersView",
  components: {
    OrderItem
  },
  data() {
    return {
      currentTab: "all",
      tabs: [
        { label: "全部订单", value: "all", count: 5 },
        { label: "待付款", value: "pending", count: 1 },
        { label: "已完成", value: "completed", count: 3 },
        { label: "已取消", value: "cancelled", count: 1 },
      ],
      orders: [
        {
          id: 1,
          orderNo: "ORD202403150001",
          productName: "ChatGPT Plus订阅",
          description: "智能AI对话助手高级版",
          price: 199,
          quantity: 1,
          status: "completed",
          statusText: "已完成",
          createTime: "2024-03-15 14:30:00",
          productImage: require("@/assets/home/chatgpt-logo.png"),
        },
        {
          id: 2,
          orderNo: "ORD202403150002",
          productName: "Midjourney会员",
          description: "AI绘画创作服务",
          price: 299,
          quantity: 1,
          status: "pending",
          statusText: "待付款",
          createTime: "2024-03-15 15:20:00",
          productImage: require("@/assets/home/midjourney-logo.png"),
        },
        {
          id: 3,
          orderNo: "ORD202403140003",
          productName: "AI写作助手",
          description: "智能文案生成工具",
          price: 159,
          quantity: 1,
          status: "cancelled",
          statusText: "已取消",
          createTime: "2024-03-14 09:15:00",
          productImage: require("@/assets/home/midjourney-logo.png"),
        }
      ],
    };
  },
  computed: {
    filteredOrders() {
      if (this.currentTab === "all") return this.orders;
      return this.orders.filter((order) => order.status === this.currentTab);
    }
  }
};
</script>

<style scoped>
.my-orders {
  min-height: 50vh;
  padding: 40px 20px;
  background: #f8f9fa;
  display: flex;
  justify-content: center;
}

.orders-card {
  background-color: #fff;
  border-radius: 16px;
  padding: 30px;
  width: 100%;
  max-width: 1060px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  position: relative;
}

.back-button {
  position: absolute;
  left: 30px;
  top: 30px;
  display: flex;
  align-items: center;
  gap: 5px;
  color: #3f5d62;
  cursor: pointer;
  font-size: 1rem;
}

.back-button:hover {
  opacity: 0.8;
}

.section-title {
  font-size: 2rem;
  color: #3f5d62;
  margin: 20px 0 40px;
  text-align: center;
}

.order-tabs {
  margin-bottom: 30px;
  text-align: center;
}

.tab-badge {
  margin-left: 6px;
}

.service-notice {
  margin-top: 40px;
  padding: 20px 25px;
  background: linear-gradient(to right, #fff9e6, #fff5d6);
  border-radius: 12px;
  border: 1px solid rgba(230, 162, 60, 0.15);
}

.notice-content {
  display: flex;
  align-items: center;
  gap: 15px;
  color: #666;
  font-size: 0.95rem;
}

.notice-content i {
  color: #e6a23c;
  font-size: 1.4rem;
}

@media (max-width: 768px) {
  .section-title {
    margin-top: 40px;
  }
}

/* 修改el-radio-button样式为主色调 */
:deep(.el-radio-button__inner) {
  border-color: #3F5D62;
  background: #fff;
  color: #3F5D62;
}

:deep(.el-radio-button__orig-radio:checked + .el-radio-button__inner) {
  background-color: #3F5D62;
  border-color: #3F5D62;
  color: #fff;
  box-shadow: -1px 0 0 0 #3F5D62;
}

:deep(.el-radio-button:first-child .el-radio-button__inner) {
  border-left-color: #3F5D62;
}

:deep(.el-radio-button__orig-radio:checked + .el-radio-button__inner:hover) {
  color: #fff;
}

:deep(.el-radio-button__inner:hover) {
  color: #3F5D62;
}
</style> 